package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"jy_go/jy_log"
	"jy_go/routers"
)

// @title API接口文档
// @version 1.0版本
// @description 简介暂无
// @termsOfService https://www.topgoer.com

// @contact.name 钧一
// @contact.url https://www.cnblogs.com/junyi-bk/
// @contact.email 2353380635

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host 127.0.0.1:8080
// @BasePath /admin
func main() {
	r := gin.Default()
	r.Use(Cors())
	r.Use(gin.Recovery())
	routers.AdminRouter(r)
	routers.HomeRouter(r)

	if err := r.Run("0.0.0.0:8080"); err != nil {
		go jy_log.JyLog("启动失败，err：" + err.Error())
		fmt.Println("启动失败：\n", err)
	}
}

//解决跨域
func Cors() gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
		c.Writer.Header().Add("Access-Control-Allow-Methods", "GET, POST, OPTIONS, DELETE")
		c.Writer.Header().Set("Access-Control-Allow-Headers", "DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding")
		c.Next()
	}
}










